﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Diablo_Character_Simulator.Enumerators;
using Diablo_Character_Simulator;

namespace Diablo_Character_Simulator
{
    public static class EHPCalculator
    {
        //Calculates effective health pool
        public static int CalculateEHP(Character character)
        {
            int rawHP = getRawHP(character.Inventory, character.BaseVitality);
            double damageReduction = 0;


            return (int)(rawHP / (1.0 - damageReduction));
        }

        private static int getRawHP(Inventory items, int baseVitality)
        {
            int totalVitality =
                (int)items.Items.SelectMany(i => i.Stats).Where(i => i.Stat == StatType.Vitality).Sum(i => i.Value);
            int lifeModifier =
                (int)items.Items.SelectMany(i => i.Stats).Where(i => i.Stat == StatType.LifePercent).Sum(i => i.Value);
            return (int)((totalVitality * 35) * ( 1 + PercentageHelper.PercToDouble(lifeModifier)));
        }

        private static double getDodge(Inventory items, int baseDexterity)
        {
            int dexterity = baseDexterity +
                (int)items.Items.SelectMany(i => i.Stats).Where(i => i.Stat == StatType.Vitality).Sum(i => i.Value);
            if (dexterity < 100) return PercentageHelper.PercToDouble(dexterity * 0.1);
            else if (dexterity < 500) return PercentageHelper.PercToDouble(7.5 + dexterity * 0.025);
            else if (dexterity < 100) return PercentageHelper.PercToDouble(10.0 + dexterity * 0.02);
            else return PercentageHelper.PercToDouble(20.0 + dexterity * 0.01);
        }

        private static int getResistance(Inventory items, StatType resistance, int baseIntelligence)
        {
            int intelligence = baseIntelligence +
                (int)items.Items.SelectMany(i => i.Stats).Where(i => i.Stat == StatType.Intelligence).Sum(i => i.Value);
            int allResistances =
                (int)items.Items.SelectMany(i => i.Stats).Where(i => i.Stat == StatType.AllResistance).Sum(i => i.Value);
            int specificResistance =
                (int)items.Items.SelectMany(i => i.Stats).Where(i => i.Stat == resistance).Sum(i => i.Value);
            return (int)(allResistances + specificResistance + intelligence * 0.1);
        }

        private static int getArmor(Inventory items, int baseStrength)
        {
            int strength = baseStrength +
                (int)items.Items.SelectMany(i => i.Stats).Where(i => i.Stat == StatType.Strength).Sum(i => i.Value);
            int armor =
                (int)items.Items.SelectMany(i => i.Stats).Where(i => i.Stat == StatType.Armor).Sum(i => i.Value);
            return strength + armor;
        }
    }
}
